<template>
  <div class="tx-log-con">
    <div v-show="txLog.length>0">
      <van-list v-model="loading"
                :finished="finished"
                :error.sync="error"
                error-text="请求失败，点击重新加载"
                finished-text=""
                @load="onLoad">
        <div v-for="(txItem,index) in txLog"
             :key="index"
             class="item-li">
          <span class="num">
            <i>{{mSymbol.name}}</i>
            {{txItem.change_num}}
          </span>
          <p class="log-info"
             v-if="txItem.status==3 && txItem.reason">
            {{txItem.status_name}}&nbsp;&nbsp;理由：{{txItem.reason}}
            <a href="javascript:;"
               class="cancle-btn"
               @click="cancelTx(txItem.user_balance_id)"
               v-if="txItem.status==0 && txItem.show_cancle==0">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;取消申请</a>
          </p>
          <p class="log-info"
             v-else>
            {{txItem.status_name}}
            <a href="javascript:;"
               class="cancle-btn"
               @click="cancelTx(txItem.user_balance_id)"
               v-if="txItem.status==0 && txItem.show_cancle==0">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;取消申请</a>
          </p>
          <p class="time">{{txItem.create_time}}</p>
        </div>
      </van-list>
    </div>
    <div v-show="!txLog.length && finished">
      <no-data :noData="noData"></no-data>
    </div>
  </div>
  
</template>

<script>
import Vue from 'vue'
import { getBalanceTxLog } from '@/api/user/member/memberApi'
import noData from '@/components/noData/index'
import { mapGetters } from 'vuex'
export default Vue.extend({
  name: 'index',
  components: {
    noData
  },
  data() {
    return {
      noData: {
        width: '184px',
        txtMarginTop: '-30px',
        img: 'https://img.wifenxiao.com/h5-wfx/images/user/no_tx_log.png',
        text: '暂无数据'
      },
      page: 1,
      txLog: [],
      error: false,
      loading: false,
      finished: false
    }
  },
  methods: {
    init() {
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 10000)
      // console.log('init2')
      this.page = 1
      this.finished = false
      this.txLog = []
      this.onLoad()
    },
    onLoad() {
      if (this.finished) { return false }
      const params = {
        act_type: true,
        p: this.page
      }
      getBalanceTxLog(params)
        .then(res => {
          this.loading = false
          this.$loadingWrap.close()
          if (res.status == 1) {
            const resData = res.data
            this.txLog.push(...resData.list)

            if (resData.list.length < 10) {
              this.finished = true
            } else {
              this.page++
            }
          } else {
            this.$Error(res.msg)
          }
        })
        .catch(() => {
          this.error = true
        })
    },
    cancelTx(id) {
      this.$emit('cancelTx', id)
    }
  },
  created() {
    this.init()
  },
  computed: {
    // 获取自定义符号
    ...mapGetters(['mSymbol'])
  }
})
</script>

<style lang="scss">
.tx-log-con {
  .no-data .h5-img {
    width: 49%!important;
  }
  .item-li {
    position: relative;
    // z-index: 11;
    border-bottom: 2px solid #f4f4f4;
    padding: 20px 0;
    font-size: 28px;
    // margin: 0 20px;
  }
  .num {
    position: absolute;
    top: 24px;
    right: 20px;
    line-height: 40px;
    color: #fd2049;
    font-size: 32px;
    font-weight: bold;
    i {
      font-size: 24px;
    }
  }
  .log-info {
    line-height: 50px;
    width: 80%;
    color: #333;
    font-size: 28px;
    .cancle-btn {
      color: #999;
    }
  }
  .time {
    line-height: 52px;
    width: 80%;
    font-size: 24px;
    color: #999;
  }
}
</style>